﻿using NFine.Application.Biz;
using NFine.Application.SystemManage;
using NFine.Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NFine.Web.Areas.BizManage.Controllers
{
    public class HuangouIntegralController : ControllerBase
    {
        //
        // GET: /BizManage/ZhongZhuanPinJian/

        private ZhongZhuanPinJianApp zhzhapp = new ZhongZhuanPinJianApp();
        private UserApp userApp = new UserApp();
        

        public ActionResult MemberIndex()
        {
            return View();
        }


        //[HttpPost]
        //[HandlerAjaxOnly]
        //[HandlerLogin]
        public ActionResult GetGridJson(Pagination pagination,string OrderTimeStart, string OrderTimeEnd, string type="-1")
        {
            DateTime dtstart = new DateTime(2000, 1, 1);
            if (!DateTime.TryParse(OrderTimeStart, out dtstart))
            {
                dtstart = new DateTime(2000, 1, 1);
            }
            DateTime dtend = DateTime.Now;
            if (!DateTime.TryParse(OrderTimeEnd, out dtend))
            {
                dtend = DateTime.Now;
            }
            dtend= dtend.AddDays(1);

            var list = zhzhapp.GetList(pagination, dtstart, dtend,int.Parse(type));
            var data = new
            {
                rows = list,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            //ViewData["curr"] = list.Count > 0 ? list[0].F_Integral : 0;
            //ViewData["dd"] = list.Where(t => t.F_JLIntegral > 0).Sum(t => t.F_JLIntegral);
            //ViewData["shy"] = list.Where(t => t.F_JLIntegral < 0).Sum(t => t.F_JLIntegral);

            return Content(data.ToJson());
        }

        public override ActionResult Form()
        {
            ViewData["TransferCenterList"] = userApp.GetZhzhUser();
            var user= OperatorProvider.Provider.GetCurrent();
            if (!user.IsSys)
                ViewData["hgInt"] = zhzhapp.GetZhZhJF(user.UserId);
            else
                ViewData["hgInt"] = 0;
            return View();
        }
        /// <summary>
        /// 会员提交换购信息
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="pjint"></param>
        /// <param name="jlint"></param>
        /// <returns></returns>
        [HttpPost]
        [HandlerLogin]
        public ActionResult SubmitForm(string uid, decimal pjint, decimal jlint)
        {
            if (zhzhapp.HGSubmitForm(uid, pjint, jlint))
            {
                return Success("积分换购完成！");
            }
            else
            {
                return Error("积分换购失败！");
            }
        }
    }
}
